package com.hk.huakangcompany.controller;

import com.github.pagehelper.PageInfo;
import com.hk.huakangcompany.commons.security.CommonResult;
import com.hk.huakangcompany.model.WxPermission;
import com.hk.huakangcompany.model.vo.ResultVO;
import com.hk.huakangcompany.service.WxPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: aerfazhe
 * @Date: 2021/7/26 10:44
 * @Statement: 权限 前端控制器
 */
@RestController
@RequestMapping("/permission")
public class WxPermissionController {

    @Autowired
    private WxPermissionService permissionService;

    //   查询所有权限 权限分配时根据type=2 只查询按钮类型权限
    @GetMapping("/pageList")
    public ResultVO<WxPermission> findAll(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit,
            WxPermission permission
    ) {
        List<WxPermission> permissionList = permissionService.findAll(page, limit, permission);
        PageInfo<WxPermission> permissionPageInfo = new PageInfo<>(permissionList);
        int count = permissionService.count(-1, -1, permission);
        if (permissionList.isEmpty()) {
            ResultVO resultVO = CommonResult.nullResultVO(count, permissionPageInfo.getList());
            return resultVO;
        }
        ResultVO resultVO = CommonResult.successResultVO(count, permissionPageInfo.getList());
        return resultVO;

    }


}
